package com.stt.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;

public class MybatisUtils {
private  static SqlSessionFactory sqlSessionFactory;
//创建静态块，启动即调用
static{
    InputStream is = null;
    try {
        //先读取蓝图
         is =Resources.getResourceAsStream("mybatis-config.xml");
        //创建工厂SqlSessionFactory
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
    } catch (IOException e) {
        e.printStackTrace();
    }


}

    public static SqlSession getSession() throws IOException{
    return sqlSessionFactory.openSession(true);
    }
}

